Skip to content

Commit 847f754

Browse files
authored
Lint: prefer Object.hasOwn, avoid eval (#39668)
1 parent 2c0f972 commit 847f754

File tree

11 files changed

+18
-20
lines changed
  • files/en-us/web

11 files changed

+18
-20
lines changed

files/en-us/web/api/htmlbuttonelement/popovertargetaction/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const toggleBtn = document.getElementById("toggleBtn");
4747

4848
// Check for popover API support.
4949
function supportsPopover() {
50-
return HTMLElement.prototype.hasOwnProperty("popover");
50+
return Object.hasOwn(HTMLElement.prototype, "popover");
5151
}
5252
```
5353

@@ -94,7 +94,7 @@ A `manual` popover must be closed explicitly, and not "light dismissed" by selec
9494

9595
```js
9696
function supportsPopover() {
97-
return HTMLElement.prototype.hasOwnProperty("popover");
97+
return Object.hasOwn(HTMLElement.prototype, "popover");
9898
}
9999

100100
const popover = document.getElementById("mypopover");

files/en-us/web/api/htmlbuttonelement/popovertargetelement/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const toggleBtn = document.getElementById("toggleBtn");
4545

4646
// Check for popover API support.
4747
function supportsPopover() {
48-
return HTMLElement.prototype.hasOwnProperty("popover");
48+
return Object.hasOwn(HTMLElement.prototype, "popover");
4949
}
5050
```
5151

files/en-us/web/api/htmlelement/popover/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ You can use the `popover` attribute to feature detect the [Popover API](/en-US/d
4242

4343
```js
4444
function supportsPopover() {
45-
return HTMLElement.prototype.hasOwnProperty("popover");
45+
return Object.hasOwn(HTMLElement.prototype, "popover");
4646
}
4747
```
4848

files/en-us/web/api/htmlelement/togglepopover/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ First we check whether popovers are supported, and if they aren't we hide the po
9595
const instructions = document.getElementById("instructions");
9696
const popover = document.getElementById("mypopover");
9797

98-
if (!HTMLElement.prototype.hasOwnProperty("popover")) {
98+
if (!Object.hasOwn(HTMLElement.prototype, "popover")) {
9999
popover.innerText = "";
100100
instructions.innerText = "Popovers not supported";
101101
}
@@ -105,7 +105,7 @@ If popovers are supported we add a listener for the `h` key to be pressed, and u
105105
We also log whether the popup was open or closed after the call, but only if a `true` or `false` was returned.
106106

107107
```js
108-
if (HTMLElement.prototype.hasOwnProperty("popover")) {
108+
if (Object.hasOwn(HTMLElement.prototype, "popover")) {
109109
document.addEventListener("keydown", (event) => {
110110
if (event.key === "h") {
111111
const popupOpened = popover.togglePopover();

files/en-us/web/api/htmlinputelement/popovertargetaction/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const toggleBtn = document.getElementById("toggleBtn");
4747

4848
// Check for popover API support.
4949
function supportsPopover() {
50-
return HTMLElement.prototype.hasOwnProperty("popover");
50+
return Object.hasOwn(HTMLElement.prototype, "popover");
5151
}
5252
```
5353

@@ -94,7 +94,7 @@ A `manual` popover must be closed explicitly, and not "light dismissed" by selec
9494

9595
```js
9696
function supportsPopover() {
97-
return HTMLElement.prototype.hasOwnProperty("popover");
97+
return Object.hasOwn(HTMLElement.prototype, "popover");
9898
}
9999

100100
const popover = document.getElementById("mypopover");

files/en-us/web/api/htmlinputelement/popovertargetelement/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ A reference to a popover element in the DOM.
2525

2626
```js
2727
function supportsPopover() {
28-
return HTMLElement.prototype.hasOwnProperty("popover");
28+
return Object.hasOwn(HTMLElement.prototype, "popover");
2929
}
3030

3131
const popover = document.getElementById("mypopover");
@@ -64,7 +64,7 @@ const toggleBtn = document.getElementById("toggleBtn");
6464

6565
// Check for popover API support.
6666
function supportsPopover() {
67-
return HTMLElement.prototype.hasOwnProperty("popover");
67+
return Object.hasOwn(HTMLElement.prototype, "popover");
6868
}
6969
```
7070

files/en-us/web/api/popover_api/using/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ The {{domxref("HTMLElement.popover")}} property can be used to get or set the [`
102102

103103
```js
104104
function supportsPopover() {
105-
return HTMLElement.prototype.hasOwnProperty("popover");
105+
return Object.hasOwn(HTMLElement.prototype, "popover");
106106
}
107107
```
108108

files/en-us/web/api/rtccertificate/getfingerprints/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ let serverFingerprintDict = Object.fromEntries(
100100
// and all common properties match.
101101
function compareObjects(obj1, obj2) {
102102
const commonProperties = Object.keys(obj1).filter((prop) =>
103-
obj2.hasOwnProperty(prop),
103+
Object.hasOwn(obj2, prop),
104104
);
105105
// Return false if there are no common properties
106106
if (Object.keys(commonProperties).length === 0) return false;

files/en-us/web/html/reference/elements/template/index.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,10 @@ In this example, a hidden support warning is included at the beginning of the ma
177177
```
178178

179179
```js
180-
const isShadowRootModeSupported =
181-
HTMLTemplateElement.prototype.hasOwnProperty("shadowRootMode");
180+
const isShadowRootModeSupported = Object.hasOwn(
181+
HTMLTemplateElement.prototype,
182+
"shadowRootMode",
183+
);
182184

183185
document
184186
.querySelector("p[hidden]")

files/en-us/web/http/guides/proxy_servers_and_tunneling/proxy_auto-configuration_pac_file/index.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,9 @@ Pattern and mask specification is done the same way as for SOCKS configuration.
243243
#### Examples
244244

245245
```js
246-
function alertEval(str) {
247-
alert(`${str} is ${eval(str)}`);
248-
}
249246
function FindProxyForURL(url, host) {
250-
alertEval('isInNet(host, "192.0.2.172", "255.255.255.255")');
251-
// "PAC-alert: isInNet(host, "192.0.2.172", "255.255.255.255") is true"
247+
alert(isInNet(host, "192.0.2.172", "255.255.255.255"));
248+
// "PAC-alert: true"
252249
}
253250
```
254251

files/en-us/web/javascript/guide/expressions_and_operators/index.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,6 @@ For methods and functions, the `typeof` operator returns results as follows:
971971
972972
```js
973973
typeof blur; // returns "function"
974-
typeof eval; // returns "function"
975974
typeof parseInt; // returns "function"
976975
typeof shape.split; // returns "function"
977976
```

0 commit comments

Comments
 (0)